package main

import (
	"fmt"
)

type list struct {
	data string
	next []*list
}

var m map[string]bool

func DFS(row []*list) {
	if len(row) == 0 {
		return
	}

	for i := range row {
		if ok, _ := m[row[i].data]; !ok {
			//!ok 代表如果这个新节点没有遇到过，那么就执行如下
			fmt.Print(row[i].data, ",")
			m[row[i].data] = true
			//做好标记 不然会重复访问
			if len(row[i].next) > 0 {
				//如果存在一个下一顶点
				DFS(row[i].next)
				//	递归继续一波DFS
			}

		}
	}

}

func main() {
	//创建邻接表
	m = make(map[string]bool)
	v0 := &list{data: "v0"}
	v1 := &list{data: "v1"}
	v2 := &list{data: "v2"}
	v3 := &list{data: "v3"}
	v4 := &list{data: "v4"}
	v5 := &list{data: "v5"}
	v6 := &list{data: "v6"}
	//	创建链接
	v0.next = append(v0.next, v1, v2, v3)
	v2.next = append(v0.next, v3)
	v3.next = append(v0.next, v4, v5, v6)
	v4.next = append(v0.next, v1)
	v6.next = append(v0.next, v2)
	fmt.Print("DFS : ")
	DFS([]*list{v0})
}
